<template>
	<view>
		<view class="cart" v-if="cart.length > 0">
			<my-address></my-address>
			<!-- 商品列表区域 -->
			<view class="top">
				<uni-icons class="shopicon" type="shop" color="#999" size="20"></uni-icons>
				<text>购物车</text>
			</view>
			<view class="goods-box">
				<uni-swipe-action>
					<uni-swipe-action-item @click="myclick(item)" :right-options="options" v-for="(item, index) in cart"
						:key="index">
						<my-goods @num-change="numchange" @radio-change="radiochange" :showNum="true" :showRadio="true"
							:item="item"></my-goods>
					</uni-swipe-action-item>
				</uni-swipe-action>
				<!-- <my-goods @num-change="numchange" @radio-change="radiochange" :showNum="true" :showRadio="true" :item="item" ></my-goods> -->

			</view>
			<my-total></my-total>
		</view>
		<view class="empty" v-else>
			<image src="../../static/cart_empty@2x.png" mode=""></image>
			<text>空空如也~</text>
		</view>
	</view>

</template>

<script>
	import mymixins from '../../mixins/mymixins.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		// 使用混入
		mixins: [mymixins],
		computed: {
			...mapState('cart', ['cart'])
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}]
			};
		},
		methods: {
			...mapMutations('cart', ['changeStatusvx', 'changeNumvx', 'delGoods']),
			// 当点击单选项时会触发
			radiochange(e) {
				console.log('radiochange', e)
				this.changeStatusvx(e)
			},
			numchange(e) {
				console.log('numchange', e);
				// 修改数量
				this.changeNumvx(e)
			},
			myclick(item) {
				this.delGoods(item.goods_id)
			},
			// 清除已经支付过的商品
			clearPayGoods(state) {
			  state.cart = state.cart.filter(item => {
			    return !item.goods_status
			  })
			}

		}
	}
</script>

<style lang="scss">
	.cart {
		padding-bottom: 100rpx;
	}

	.top {
		height: 88rpx;
		line-height: 88rpx;
		border-bottom: 1px solid #ddd;

		.shopicon {
			margin-left: 32rpx;
			margin-right: 12rpx;
		}
	}

	.goods-box {}
	.empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 200rpx;
		image {
			width: 200rpx;
			height: 200rpx;
		}
		text {
			font-size: 12px;
			color: #858585;
			margin-top: 20rpx;
		}
	}
</style>
